package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.system.System;
	import flash.text.Font;
	import flash.text.TextFormat;
	
	import qnx.ui.core.Container;
	import qnx.ui.core.ContainerAlign;
	import qnx.ui.core.ContainerFlow;
	import qnx.ui.core.SizeMode;
	import qnx.ui.core.Spacer;
	import qnx.ui.data.DataProvider;
	import qnx.ui.events.ListEvent;
	import qnx.ui.listClasses.List;
	import qnx.ui.listClasses.ListSelectionMode;
	import qnx.ui.listClasses.ScrollDirection;
	import qnx.ui.text.Label;
	import qnx.ui.text.TextInput;
	
	[SWF(height="600", width="1024", frameRate="30", backgroundColor="#FFFFFF")]
	public class PBFontSample extends Sprite
	{
		private var mainContainer:Container;
		private var fontSample:Label;
		private var fontList:List;
		
		public function PBFontSample()
		{
			super();
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;

			buildUI();
		}
		
		private function buildUI():void{
			mainContainer = new Container();
			mainContainer.flow = ContainerFlow.VERTICAL;
			mainContainer.align=ContainerAlign.NEAR;
			mainContainer.debugColor=0xFF0000;
			mainContainer.margins = Vector.<Number>([10,10,10,10]);
			//mainContainer.height = stage.stageHeight;
			//mainContainer.width = stage.stageWidth;
			/*var titleTextFormat:TextFormat = new TextFormat();
			titleTextFormat.size = 14;
			titleTextFormat.bold = true;
			titleTextFormat.font
			var titleLabel:Label = new Label();
			titleLabel.text = "ToDo List";
			mainContainer.addChild(titleLabel);
			mainContainer.opaqueBackground = 0x999900;
			
			var spacer:Spacer = null;
			spacer = new Spacer();
			mainContainer.addChild(spacer);
			
			var ti:TextInput = new TextInput();
			//ti.sizeMode = SizeMode.BOTH;
			mainContainer.addChild(ti);
			*/
			
			var fonts:Array = flash.text.Font.enumerateFonts(true);
			trace(fonts.length);
			
			var f:Font;
			var arr:Array = new Array();
			for each(f in fonts){
				arr.push({label:f.fontName.toString()});
			}
			
			
			fontList = new List();
			fontList.width=1024;
			fontList.height=560;
			fontList.scrollDirection = ScrollDirection.VERTICAL;
			fontList.selectionMode = ListSelectionMode.SINGLE;
			fontList.dataProvider = new DataProvider(arr);
			fontList.addEventListener(ListEvent.ITEM_CLICKED, onListItemClicked);
			
			mainContainer.addChild(fontList);
			
			fontSample = new Label();
			fontSample.text = "The quick brown fox jumped over the lazy dog.";
			fontSample.setPosition(0, 560);
			fontSample.width=1024;
			fontSample.height = 40;
			mainContainer.addChild(fontSample);
			
			addChild(mainContainer);
		}
		
		public function onListItemClicked(event:ListEvent):void{
			var tf:TextFormat = new TextFormat();
			tf.font = fontList.selectedItem.label;
			
			fontSample.format = tf;
		}
	}
}